package flirtme.activities;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

import com.ans.flirtme.R;

import flirtme.constants.Constants;
import flirtme.libraries.imageloader.ImageLoader;
import flirtme.managers.UserManager;
import flirtme.model.BroadcastMessage;
import flirtme.model.Message;

public class BroadcastMessageActivity extends Activity {
	
	private BroadcastMessage message;
	
	private TextView senderName;
	private TextView senderAddress;
	private TextView messageBody;	 
	private ImageView imageView;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_broadcast_message_view);
		
		initUIControls();
		initMessage();
		
		if (message != null) {
			putUIControlsData();
		} else {
			//TODO Ver q hacer en este caso
		}
	}

	private void initUIControls() {
		senderName = (TextView) findViewById(R.id.bc_message_sender_name);
		senderAddress = (TextView) findViewById(R.id.bc_message_sender_address);
		messageBody = (TextView) findViewById(R.id.bc_message_body);
		imageView = (ImageView) findViewById(R.id.bc_message_sender_avatar);
		
		Intent intent = this.getIntent();
		String avatarUrl = intent.getStringExtra(Constants.AVATAR_URL);
		String senderNameString = intent.getStringExtra(Constants.SENDER_ID);
		String text = intent.getStringExtra(Constants.MESSAGE_ID_KEY);
		String address = intent.getStringExtra(Constants.ADDRESS);
		ImageLoader imageLoader = new ImageLoader(this);
		imageLoader.DisplayImage(avatarUrl,  imageView);
		
		senderName.setText(senderNameString);
		messageBody.setText(text);
		senderAddress.setText(address);
	}

	private void initMessage() {
//		Long messageId = null;
//		Intent intent = getIntent();
//		String stringMessageId = intent.getStringExtra(Constants.MESSAGE_ID_KEY);
//		if (stringMessageId != null) {
//			messageId = Long.valueOf(stringMessageId);
//		}
//		Message mockMessage = new Message();
//		mockMessage.setId(messageId);
//		
//		int index = UserManager.instance().getBroadcastMessages().indexOf(mockMessage);
//		if (index != -1) {
//			message = UserManager.instance().getBroadcastMessages().get(index);			
//		} else {
//			message = null;
//		}
	}

	private void putUIControlsData() {
		senderName.setText(message.getSender().getName());
		senderAddress.setText("Calle Falsa 123"); //TODO Ver que info se guarda de las empresas y llenar este campo apropiadamente
		messageBody.setText(message.getBody());
	}

}
